﻿using System;
using System.Text;
using System.Linq;
using Morus;
using NUnit;
using NUnit.Framework;

namespace KAKA.Test
{
    [TestFixture]
    public class CryptoTestFixture
    {
        [Test]
        public void Encrypt_Test()
        {
            var a = Guid.NewGuid();
            var b = a.Shrink();
            var c = Convert.ToBase64String(a.ToByteArray());
            var key = "H@OH@OXUEX1, T1@NT1@NX1@NGSH@NG.";
            key.Select(r => string.Format("{0:x}", (int)r)).ToList().ForEach(r =>
            {
                Console.Write(r);
            });
            Console.WriteLine();
            var crypto = new Cryptography(key);
            var source = "13800138000";
            var iv = crypto.GenerateSalt();
            var encrypt = crypto.Encrypt(source, iv);

            Console.WriteLine(string.Format("a : {0}", a));
            Console.WriteLine(string.Format("b : {0}", b));
            Console.WriteLine(string.Format("c : {0}", c));
            Console.WriteLine(string.Format("source : {0}", source));
            Console.WriteLine(string.Format("encrypt: {0}", Convert.ToBase64String(encrypt)));
            Console.WriteLine(string.Format("key    : {0}", key));
            Console.WriteLine(string.Format("iv     : {0}", Convert.ToBase64String(iv)));

            var decrypt = crypto.Decrypt(encrypt, iv);
            Console.WriteLine(string.Format("decrypt: {0}", decrypt));

            Assert.AreEqual(source, decrypt);
        }


    }
}
